#!/bin/bash

if [ -z $1 ] || [ -z $2 ] || [ ! -d $2 ]; then
	echo error
else
	key=$1
	path=$2
fi

temp=$(pwd)

echo $key
echo $path

cd $path

# 递归函数的实现
function search()
{
	dirlist=$(ls)
	for f in $dirlist
		do
			if [ -d "$f" ]; then
				#echo start enter: $f
				cd $f
				search
				cd ..
			else
				echo file is $f
				#if [ $f == "*.java" ]; then
					grep -n $key $f
				#fi
			fi
		done
}

search
cd $temp
